package controllers

import (
	"fmt"
	"github.com/astaxie/beego"
	"html/template"
	"strconv"
	"xianzhi/service"
	"xianzhi/utils"
)

type OrderSchoolController struct {
	BaseController
}

// 公共空间
func (c *OrderSchoolController) PublicSpace() {
	userId := c.GetSession("userId")
	key := fmt.Sprintf("selected_%d", userId)
	c.SetSession(key, "")

	p := map[string]interface{}{}
	p["level"] = 2
	_, cityList := service.GetRegionList(p)
	c.Data["cityList"] = cityList

	cityId := c.GetString("city_id")
	c.Data["cityId"] = utils.Atoi64(cityId)
	name := c.GetString("name")
	c.Data["name"] = name

	c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
	c.TplName = "order_school/public_space.html"
}

func (c *OrderSchoolController) LoadMore() {
	userId := c.GetSession("userId")
	count, _ := beego.AppConfig.Int("loadcount")
	curPage, _ := strconv.Atoi(c.GetString("p"))
	if curPage <= 0 {
		curPage = 1
	}
	p := map[string]interface{}{}
	p["relation"] = true
	cityId := c.GetString("city_id")
	if len(cityId) > 0 {
		p["cityId"] = cityId
	}
	name := c.GetString("name")
	if len(name) > 0 {
		p["name"] = name
	}
	p["curPage"] = curPage
	p["perCount"] = count
	p["userId"] = userId
	_, orderSchoolList := service.GetOrderSchoolList(p)
	c.Data["orderSchoolList"] = orderSchoolList
	c.TplName = "order_school/load_more_public_space.html"
}

// 勾选历史
func (c *OrderSchoolController) SelectedHistory() {
	userId := c.GetSession("userId")

	p := map[string]interface{}{}
	p["isExcellent"] = 1
	p["userId"] = userId
	c.Data["excellentSchoolNum"], c.Data["excellentSchoolList"] = service.GetOrderSchoolList(p)

	p = map[string]interface{}{}
	p["isAssist"] = 1
	p["userId"] = userId
	c.Data["assistSchoolNum"], c.Data["assistSchoolList"] = service.GetOrderSchoolList(p)

	c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
	c.TplName = "order_school/selected_history.html"
}